<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Vue | 冲冲冲</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/wxb-blog/touXiang.jpg">
    <meta name="description" content="前端知识点整理">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/wxb-blog/assets/css/0.styles.c4047da6.css" as="style"><link rel="preload" href="/wxb-blog/assets/js/app.8c0fb757.js" as="script"><link rel="preload" href="/wxb-blog/assets/js/4.900b5326.js" as="script"><link rel="preload" href="/wxb-blog/assets/js/1.627dfec7.js" as="script"><link rel="preload" href="/wxb-blog/assets/js/118.b53a6516.js" as="script"><link rel="prefetch" href="/wxb-blog/assets/js/10.5da366e1.js"><link rel="prefetch" href="/wxb-blog/assets/js/100.6a0e9515.js"><link rel="prefetch" href="/wxb-blog/assets/js/101.0a4f1ddb.js"><link rel="prefetch" href="/wxb-blog/assets/js/102.f8294266.js"><link rel="prefetch" href="/wxb-blog/assets/js/103.7487022c.js"><link rel="prefetch" href="/wxb-blog/assets/js/104.11246d00.js"><link rel="prefetch" href="/wxb-blog/assets/js/105.f716509d.js"><link rel="prefetch" href="/wxb-blog/assets/js/106.58efb93a.js"><link rel="prefetch" href="/wxb-blog/assets/js/107.62d831d4.js"><link rel="prefetch" href="/wxb-blog/assets/js/108.583b5a2d.js"><link rel="prefetch" href="/wxb-blog/assets/js/109.1209ce30.js"><link rel="prefetch" href="/wxb-blog/assets/js/11.31bc45c0.js"><link rel="prefetch" href="/wxb-blog/assets/js/110.2269d67b.js"><link rel="prefetch" href="/wxb-blog/assets/js/111.c9798d51.js"><link rel="prefetch" href="/wxb-blog/assets/js/112.50a5b1d8.js"><link rel="prefetch" href="/wxb-blog/assets/js/113.a138b788.js"><link rel="prefetch" href="/wxb-blog/assets/js/114.30231cae.js"><link rel="prefetch" href="/wxb-blog/assets/js/115.01c0d6b9.js"><link rel="prefetch" href="/wxb-blog/assets/js/116.3b80b466.js"><link rel="prefetch" href="/wxb-blog/assets/js/117.48830aa8.js"><link rel="prefetch" href="/wxb-blog/assets/js/119.271b5e67.js"><link rel="prefetch" href="/wxb-blog/assets/js/12.a84c083f.js"><link rel="prefetch" href="/wxb-blog/assets/js/120.829532de.js"><link rel="prefetch" href="/wxb-blog/assets/js/121.5e6b5cc1.js"><link rel="prefetch" href="/wxb-blog/assets/js/122.ec3253a7.js"><link rel="prefetch" href="/wxb-blog/assets/js/123.d97dcb4a.js"><link rel="prefetch" href="/wxb-blog/assets/js/124.0a2ebde2.js"><link rel="prefetch" href="/wxb-blog/assets/js/125.2325b4c3.js"><link rel="prefetch" href="/wxb-blog/assets/js/13.b0f2669d.js"><link rel="prefetch" href="/wxb-blog/assets/js/14.ec9b0c28.js"><link rel="prefetch" href="/wxb-blog/assets/js/15.73531217.js"><link rel="prefetch" href="/wxb-blog/assets/js/16.caa982f1.js"><link rel="prefetch" href="/wxb-blog/assets/js/17.a3080f70.js"><link rel="prefetch" href="/wxb-blog/assets/js/18.3ed83fbe.js"><link rel="prefetch" href="/wxb-blog/assets/js/19.c6d34143.js"><link rel="prefetch" href="/wxb-blog/assets/js/20.1dbc75a7.js"><link rel="prefetch" href="/wxb-blog/assets/js/21.0b017963.js"><link rel="prefetch" href="/wxb-blog/assets/js/22.1add63ec.js"><link rel="prefetch" href="/wxb-blog/assets/js/23.29eb7ce7.js"><link rel="prefetch" href="/wxb-blog/assets/js/24.1acc14c0.js"><link rel="prefetch" href="/wxb-blog/assets/js/25.4336e0d3.js"><link rel="prefetch" href="/wxb-blog/assets/js/26.0f25ef0b.js"><link rel="prefetch" href="/wxb-blog/assets/js/27.610e84a6.js"><link rel="prefetch" href="/wxb-blog/assets/js/28.46cdd718.js"><link rel="prefetch" href="/wxb-blog/assets/js/29.979ca3bb.js"><link rel="prefetch" href="/wxb-blog/assets/js/30.ea83a5c0.js"><link rel="prefetch" href="/wxb-blog/assets/js/31.e3e3d825.js"><link rel="prefetch" href="/wxb-blog/assets/js/32.aa79659d.js"><link rel="prefetch" href="/wxb-blog/assets/js/33.519bc533.js"><link rel="prefetch" href="/wxb-blog/assets/js/34.532535b1.js"><link rel="prefetch" href="/wxb-blog/assets/js/35.d9c1cc94.js"><link rel="prefetch" href="/wxb-blog/assets/js/36.8d328510.js"><link rel="prefetch" href="/wxb-blog/assets/js/37.c5ee763c.js"><link rel="prefetch" href="/wxb-blog/assets/js/38.33cc76ee.js"><link rel="prefetch" href="/wxb-blog/assets/js/39.7d0f943e.js"><link rel="prefetch" href="/wxb-blog/assets/js/40.67486ae5.js"><link rel="prefetch" href="/wxb-blog/assets/js/41.5c5ebfd0.js"><link rel="prefetch" href="/wxb-blog/assets/js/42.f5596c7b.js"><link rel="prefetch" href="/wxb-blog/assets/js/43.32e8db11.js"><link rel="prefetch" href="/wxb-blog/assets/js/44.3bd8001e.js"><link rel="prefetch" href="/wxb-blog/assets/js/45.65f5b1ae.js"><link rel="prefetch" href="/wxb-blog/assets/js/46.45fc8464.js"><link rel="prefetch" href="/wxb-blog/assets/js/47.459c158e.js"><link rel="prefetch" href="/wxb-blog/assets/js/48.a11bfe4f.js"><link rel="prefetch" href="/wxb-blog/assets/js/49.9c30d506.js"><link rel="prefetch" href="/wxb-blog/assets/js/5.fb67145f.js"><link rel="prefetch" href="/wxb-blog/assets/js/50.4e4774a6.js"><link rel="prefetch" href="/wxb-blog/assets/js/51.9a1b5ee4.js"><link rel="prefetch" href="/wxb-blog/assets/js/52.63ea264a.js"><link rel="prefetch" href="/wxb-blog/assets/js/53.84a598c3.js"><link rel="prefetch" href="/wxb-blog/assets/js/54.a4b338f0.js"><link rel="prefetch" href="/wxb-blog/assets/js/55.e8702b05.js"><link rel="prefetch" href="/wxb-blog/assets/js/56.9f6390ba.js"><link rel="prefetch" href="/wxb-blog/assets/js/57.59f004d1.js"><link rel="prefetch" href="/wxb-blog/assets/js/58.41470fa8.js"><link rel="prefetch" href="/wxb-blog/assets/js/59.b48e3490.js"><link rel="prefetch" href="/wxb-blog/assets/js/6.4c0abb46.js"><link rel="prefetch" href="/wxb-blog/assets/js/60.4c84f1b7.js"><link rel="prefetch" href="/wxb-blog/assets/js/61.ae0fe02f.js"><link rel="prefetch" href="/wxb-blog/assets/js/62.b4e4a1e6.js"><link rel="prefetch" href="/wxb-blog/assets/js/63.ec0dee52.js"><link rel="prefetch" href="/wxb-blog/assets/js/64.3d6d64aa.js"><link rel="prefetch" href="/wxb-blog/assets/js/65.c669dbe2.js"><link rel="prefetch" href="/wxb-blog/assets/js/66.47a199e3.js"><link rel="prefetch" href="/wxb-blog/assets/js/67.b96f5161.js"><link rel="prefetch" href="/wxb-blog/assets/js/68.f2917e43.js"><link rel="prefetch" href="/wxb-blog/assets/js/69.1f0baea0.js"><link rel="prefetch" href="/wxb-blog/assets/js/7.e2ab66a8.js"><link rel="prefetch" href="/wxb-blog/assets/js/70.4f25a08f.js"><link rel="prefetch" href="/wxb-blog/assets/js/71.b319631d.js"><link rel="prefetch" href="/wxb-blog/assets/js/72.e0191932.js"><link rel="prefetch" href="/wxb-blog/assets/js/73.ecb5024d.js"><link rel="prefetch" href="/wxb-blog/assets/js/74.c6e1feec.js"><link rel="prefetch" href="/wxb-blog/assets/js/75.6daefc45.js"><link rel="prefetch" href="/wxb-blog/assets/js/76.ae253459.js"><link rel="prefetch" href="/wxb-blog/assets/js/77.aeeda56a.js"><link rel="prefetch" href="/wxb-blog/assets/js/78.acbdc69b.js"><link rel="prefetch" href="/wxb-blog/assets/js/79.06ee3013.js"><link rel="prefetch" href="/wxb-blog/assets/js/8.457c5be9.js"><link rel="prefetch" href="/wxb-blog/assets/js/80.3e6d4caf.js"><link rel="prefetch" href="/wxb-blog/assets/js/81.e34252a0.js"><link rel="prefetch" href="/wxb-blog/assets/js/82.c2c5018f.js"><link rel="prefetch" href="/wxb-blog/assets/js/83.98e1596b.js"><link rel="prefetch" href="/wxb-blog/assets/js/84.ad81eee2.js"><link rel="prefetch" href="/wxb-blog/assets/js/85.b9f50159.js"><link rel="prefetch" href="/wxb-blog/assets/js/86.02892036.js"><link rel="prefetch" href="/wxb-blog/assets/js/87.46d2a524.js"><link rel="prefetch" href="/wxb-blog/assets/js/88.c4be6ad8.js"><link rel="prefetch" href="/wxb-blog/assets/js/89.6a428824.js"><link rel="prefetch" href="/wxb-blog/assets/js/9.23625e81.js"><link rel="prefetch" href="/wxb-blog/assets/js/90.56b8afcf.js"><link rel="prefetch" href="/wxb-blog/assets/js/91.362cd602.js"><link rel="prefetch" href="/wxb-blog/assets/js/92.73449f51.js"><link rel="prefetch" href="/wxb-blog/assets/js/93.4867589e.js"><link rel="prefetch" href="/wxb-blog/assets/js/94.54b5078f.js"><link rel="prefetch" href="/wxb-blog/assets/js/95.5d023adf.js"><link rel="prefetch" href="/wxb-blog/assets/js/96.35a29d7f.js"><link rel="prefetch" href="/wxb-blog/assets/js/97.3ce9e9b3.js"><link rel="prefetch" href="/wxb-blog/assets/js/98.b9799210.js"><link rel="prefetch" href="/wxb-blog/assets/js/99.4ed8d1d2.js"><link rel="prefetch" href="/wxb-blog/assets/js/vendors~flowchart.dea86b1a.js">
    <link rel="stylesheet" href="/wxb-blog/assets/css/0.styles.c4047da6.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-7dd95ae2><div data-v-7dd95ae2><div class="password-shadow password-wrapper-out" style="display:none;" data-v-59e6cb88 data-v-7dd95ae2 data-v-7dd95ae2><h3 class="title" data-v-59e6cb88>冲冲冲</h3> <p class="description" data-v-59e6cb88>前端知识点整理</p> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>wxb</span>
          
        <span data-v-59e6cb88>2022 - </span>
        2023
      </a></span></div></div> <div class="hide" data-v-7dd95ae2><header class="navbar" data-v-7dd95ae2><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/wxb-blog/" class="home-link router-link-active"><img src="/wxb-blog/touXiang.jpg" alt="冲冲冲" class="logo"> <span class="site-name">冲冲冲</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/wxb-blog/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/Css/" class="nav-link"><i class="undefined"></i>
  Css
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/Docker/" class="nav-link"><i class="undefined"></i>
  Docker
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/HTML/" class="nav-link"><i class="undefined"></i>
  HTML
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/Javascript/" class="nav-link"><i class="undefined"></i>
  Javascript
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/React/" class="nav-link"><i class="undefined"></i>
  React
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/uniapp项目/" class="nav-link"><i class="undefined"></i>
  uniapp项目
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/Vue/" class="nav-link"><i class="undefined"></i>
  Vue
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/项目/" class="nav-link"><i class="undefined"></i>
  项目
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/Vue3/" class="nav-link"><i class="undefined"></i>
  Vue3
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/插件库/" class="nav-link"><i class="undefined"></i>
  插件库
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/工具/" class="nav-link"><i class="undefined"></i>
  工具
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/开源项目/" class="nav-link"><i class="undefined"></i>
  开源项目
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/面试题/" class="nav-link"><i class="undefined"></i>
  面试题
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/面试问/" class="nav-link"><i class="undefined"></i>
  面试问
</a></li></ul></div></div><div class="nav-item"><a href="/wxb-blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      王xb
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/wxb666" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-7dd95ae2></div> <aside class="sidebar" data-v-7dd95ae2><div class="personal-info-wrapper" data-v-1fad0c41 data-v-7dd95ae2><img src="/wxb-blog/touXiang.jpg" alt="author-avatar" class="personal-img" data-v-1fad0c41> <h3 class="name" data-v-1fad0c41>
    wxb
  </h3> <div class="num" data-v-1fad0c41><div data-v-1fad0c41><h3 data-v-1fad0c41>112</h3> <h6 data-v-1fad0c41>Articles</h6></div> <div data-v-1fad0c41><h3 data-v-1fad0c41>22</h3> <h6 data-v-1fad0c41>Tags</h6></div></div> <ul class="social-links" data-v-1fad0c41></ul> <hr data-v-1fad0c41></div> <nav class="nav-links"><div class="nav-item"><a href="/wxb-blog/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/Css/" class="nav-link"><i class="undefined"></i>
  Css
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/Docker/" class="nav-link"><i class="undefined"></i>
  Docker
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/HTML/" class="nav-link"><i class="undefined"></i>
  HTML
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/Javascript/" class="nav-link"><i class="undefined"></i>
  Javascript
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/React/" class="nav-link"><i class="undefined"></i>
  React
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/uniapp项目/" class="nav-link"><i class="undefined"></i>
  uniapp项目
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/Vue/" class="nav-link"><i class="undefined"></i>
  Vue
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/项目/" class="nav-link"><i class="undefined"></i>
  项目
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/Vue3/" class="nav-link"><i class="undefined"></i>
  Vue3
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/插件库/" class="nav-link"><i class="undefined"></i>
  插件库
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/工具/" class="nav-link"><i class="undefined"></i>
  工具
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/开源项目/" class="nav-link"><i class="undefined"></i>
  开源项目
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/面试题/" class="nav-link"><i class="undefined"></i>
  面试题
</a></li><li class="dropdown-item"><!----> <a href="/wxb-blog/categories/面试问/" class="nav-link"><i class="undefined"></i>
  面试问
</a></li></ul></div></div><div class="nav-item"><a href="/wxb-blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      王xb
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/wxb666" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="undefined"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-59e6cb88 data-v-7dd95ae2><h3 class="title" data-v-59e6cb88>Vue</h3> <!----> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>wxb</span>
          
        <span data-v-59e6cb88>2022 - </span>
        2023
      </a></span></div></div> <div data-v-7dd95ae2><div data-v-7dd95ae2><main class="page"><section style="display:;"><div class="page-title"><h1 class="title">Vue</h1> <div data-v-8a445198><i class="iconfont reco-account" data-v-8a445198><span data-v-8a445198>王xb</span></i> <i class="iconfont reco-date" data-v-8a445198><span data-v-8a445198>2/7/2023</span></i> <!----> <i class="tags iconfont reco-tag" data-v-8a445198><span class="tag-item" data-v-8a445198>面试题</span></i></div></div> <div class="theme-reco-content content__default"><p>https://www.cnblogs.com/Mochenghualei/category/2203718.html</p> <h2 id="基础"><a href="#基础" class="header-anchor">#</a> 基础</h2> <h3 id="生命周期"><a href="#生命周期" class="header-anchor">#</a> 生命周期</h3> <h5 id="问一-第一次页面加载会触发哪几个钩子"><a href="#问一-第一次页面加载会触发哪几个钩子" class="header-anchor">#</a> 问一：第一次页面加载会触发哪几个钩子</h5> <p>答：beforeCreate， created， beforeMount， mounted</p> <h5 id="问二-created和mounted的区别"><a href="#问二-created和mounted的区别" class="header-anchor">#</a> 问二：created和mounted的区别</h5> <p>created在模板渲染成html前调用，通常是调用接口获取数据，初始化某些属性值，然后再渲染成视图。</p> <p>mounted:在模板渲染成html后调用，通常是初始化页面完成后，再对html的dom节点进行一些需要的操作。</p> <h5 id="问三-vue子组件和父组件创建和挂载顺序"><a href="#问三-vue子组件和父组件创建和挂载顺序" class="header-anchor">#</a> 问三：Vue子组件和父组件创建和挂载顺序</h5> <p>答：父beforeCreate-&gt;父created-&gt;父beforeMount-&gt;子beforeCreate-&gt;子created-&gt;子beforeMount-&gt;子mounted-&gt;父mounted</p> <h3 id="watch"><a href="#watch" class="header-anchor">#</a> watch</h3> <h5 id="监听整个对象"><a href="#监听整个对象" class="header-anchor">#</a> 监听整个对象</h5> <p>**缺点:**给对象的所有属性都加上这个监听器，但是这样性能开销就会非常大了，任何修改obj里面任何一个属性都会触发这个监听器里的 handler</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>watch: {
    form: {
      handler () { //这是vue的规定写法，当你watch的值发生变化的时候，就会触发这个handler，这是vue内部帮你做的事情
        console.log(this.form.age)
      },
      deep: true,  // 可以深度检测到 obj 对象的属性值的变化
      immediate: true //刷新加载  立马触发一次handler
    }
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h5 id="只监听单一属性"><a href="#只监听单一属性" class="header-anchor">#</a> 只监听单一属性</h5> <div class="language- line-numbers-mode"><pre class="language-text"><code>watch: {
    'form.age': {
      handler () {
        console.log(this.form.age)
      }
    }
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h4 id="watch和computed区别"><a href="#watch和computed区别" class="header-anchor">#</a> watch和computed区别</h4> <ol><li>computed支持缓存，只有依赖发生改变时，才重新计算。watch 不支持缓存，数据变，直接会触发相应的操作。</li> <li>computed 不支持异步，当computed内有异步操作时无效，无法监听数据的变化；watch 支持异步。</li></ol> <h5 id="两者如何使用"><a href="#两者如何使用" class="header-anchor">#</a> 两者如何使用：</h5> <ol><li>如果一个数据依赖于其他数据进计算而来的，那么应该使用computed，最典型的栗子： 购物车商品结算的时候</li> <li>如果需要在某个数据变化时做逻辑处理，就使用watch，栗子：搜索数据</li></ol> <h3 id="组件之间传值通信方法有哪些"><a href="#组件之间传值通信方法有哪些" class="header-anchor">#</a> 组件之间传值通信方法有哪些：</h3> <p>https://blog.csdn.net/xm1037782843/article/details/128027132</p> <ol><li>props</li> <li>$emit/$on</li> <li>$refs</li> <li>$parents/$children</li> <li>Vuex</li> <li>……</li></ol> <h4 id="双向绑定原理"><a href="#双向绑定原理" class="header-anchor">#</a> 双向绑定原理</h4> <h5 id="什么是双向绑定"><a href="#什么是双向绑定" class="header-anchor">#</a> 什么是双向绑定：</h5> <p>​	数据既能从data流向页面，还可以从页面流向data</p> <h5 id="原理"><a href="#原理" class="header-anchor">#</a> 原理：</h5> <p>​		答：vue 双向数据绑定是通过 数据劫持 结合 发布订阅模式的方式来实现的， 也就是说数据和视图同步，数据发生变化，视图跟着变化，视图变化，数据也随之发生改变；
核心：关于VUE双向数据绑定，其核心是Object.defineProperty()方法。</p> <h4 id="object-defineproperty实现数据劫持-有什么缺陷-如何解决。"><a href="#object-defineproperty实现数据劫持-有什么缺陷-如何解决。" class="header-anchor">#</a> Object.defineProperty实现数据劫持，有什么缺陷，如何解决。</h4> <p>​	<strong>缺陷：</strong></p> <ol><li>无法检测到对象属性的新增或删除，给对象新增属性，触发不了组件的重新渲染</li> <li>无法监听数组变化，通过数组下标的方式修改数组，触发不了组件的重新渲染</li></ol> <p>​	**为什么会这样：**object.defineProperty 只能劫持对象的属性，从而需要对对象每个属性进行遍历，如果属性值是对象，还需要深度遍历。Proxy 可以劫持整个对象，并返回一个新的对象</p> <p>​	<strong>解决：</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">this</span><span class="token punctuation">.</span>obj <span class="token operator">=</span> Object<span class="token punctuation">.</span><span class="token function">assign</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token keyword">this</span><span class="token punctuation">.</span>obj<span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token literal-property property">b</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token literal-property property">e</span><span class="token operator">:</span> <span class="token number">2</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$set</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>obj<span class="token punctuation">,</span><span class="token string">'f'</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span>
<span class="token keyword">this</span><span class="token punctuation">.</span>obj <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token operator">...</span><span class="token keyword">this</span><span class="token punctuation">.</span>obj<span class="token punctuation">,</span><span class="token operator">...</span><span class="token punctuation">{</span> <span class="token literal-property property">b</span><span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token literal-property property">e</span><span class="token operator">:</span> <span class="token number">2</span> <span class="token punctuation">}</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h5 id="问-vue3中是如何解决的"><a href="#问-vue3中是如何解决的" class="header-anchor">#</a> 问：vue3中是如何解决的？</h5> <p>​	Vue3 将使用 ES6的Proxy 作为其观察者机制，取代之前使用的Object.defineProperty</p> <p>​	在 Vue3 中通过使用 Proxy 对对象进行代理，从而实现数据劫持。使用Proxy 的好处是它可以完美的监听到任何方式的数据改变，唯一的缺点是兼容性的问题，因为 Proxy 是 ES6 的语法</p> <h3 id="v-for中key有什么作用"><a href="#v-for中key有什么作用" class="header-anchor">#</a> v-for中key有什么作用</h3> <ol><li>当数组发生增删时， 默认需要把发生改动的项目全部进行重绘, 浪费资源</li> <li>key来给每个节点做一个唯一标识，一旦发生 增删操作之后，重绘之前会检测新绘制的元素和已有的元素是否存在相同的key，相同则复用，Diff算法就可以正确的识别此节点。作用主要是为了高效的更新虚拟DOM</li></ol> <h3 id="nexttick的作用与原理"><a href="#nexttick的作用与原理" class="header-anchor">#</a> nextTick的作用与原理</h3> <p>答题思路：</p> <ul><li>1.nextTick是做什么的？</li> <li>2.为什么需要它呢？</li> <li>3.开发时何时使用它？</li></ul> <p>回答范例：</p> <ul><li>1.定义：nextTick是等待下一次DOM更新刷新的工具方法；</li> <li>2.为什么使用：Vue有个异步更新策略，意思是如果数据变化，Vue不会立刻更新DOM，而是开启一个队列，把组件更新函数保存在队列中，在同一事件循环中发生的所有数据变更会异步的批量更新。这一策略导致我们对数据的修改不会立刻体现在DOM上，此时如果想要获取更新后的DOM状态，就需要使用nextTick；</li> <li>3.开发时，有两个场景我们会用到nextTick：
<ul><li>created中想要获取DOM时；</li> <li>响应式数据变化后获取DOM更新后的状态，比如希望获取列表更新后的高度</li></ul></li></ul> <h3 id="vue-router"><a href="#vue-router" class="header-anchor">#</a> Vue-router</h3> <h5 id="vue-router的两种模式"><a href="#vue-router的两种模式" class="header-anchor">#</a> vue-router的两种模式</h5> <ol><li>hash模式</li> <li>history模式</li></ol> <p><strong>思路</strong></p> <ul><li>总述两者区别;</li> <li>详细阐述使用细节;</li> <li>实现方式;</li></ul> <p><strong>回答范例</strong></p> <ul><li>vue-router有3个模式，其中history和hash更为常用。两者差别主要在显示形式和部署上；</li> <li>hash模式在地址栏显示的时候是以哈希的形式显示：#/xxx，这种方式使用和部署都比较简单；history模式url看起来更优雅美观，但是应用在部署时需要做特殊配置，web服务器需要做回退处理，否则会出现刷新页面404的问题；</li> <li>在实现上不管哪种模式，最终都是通过监听popstate事件触发路由跳转处理，url显示不同只是显示效果上的差异；</li></ul> <h2 id="项目"><a href="#项目" class="header-anchor">#</a> 项目</h2> <h3 id="项目如何性能优化"><a href="#项目如何性能优化" class="header-anchor">#</a> 项目如何性能优化</h3> <ol><li>UI框架按需加载</li> <li>路由懒加载</li> <li>图片懒加载</li> <li><code>keep-alive</code>缓存页面：避免重复创建组件实例</li> <li>CDN引入第三方库</li> <li>开启GZip压缩（配置本地config和服务器的nginx）</li> <li>长列表性能优化：如果是大数据长列表，可采用虚拟滚动，只渲染少部分可视区域的内容</li> <li>合适时机使用<code>v-once</code>和<code>v-memo</code></li> <li>v-show替换v-if：避免重复创建组件,怎家开销</li></ol> <h3 id="如何做权限管理"><a href="#如何做权限管理" class="header-anchor">#</a> 如何做权限管理</h3> <p><strong>页面权限:</strong></p> <p>​	1.**纯前端方案(比较low)😗*所有路由信息在前端配置,</p> <p>​	2.**服务端方案:**后端方案会把所有页面路由信息存在数据库中，用户登录的时候根据其角色查询得到其能访问的所有页面路由信息返回给前端，前端再通过addRoutes动态添加路由信息</p> <p><strong>按钮权限:</strong></p> <p>​	按钮权限的控制通常会实现一个指令，将按钮要求角色通过值传给v-permission指令，在指令的moutned钩子中可以判断当前用户角色和按钮是否存在交集，有则保留按钮，无则移除按钮（是DOM操作）</p> <h3 id="如何修改element-ui默认样式"><a href="#如何修改element-ui默认样式" class="header-anchor">#</a> 如何修改element-ui默认样式</h3> <h5 id="去掉scoped-但会污染全局样式"><a href="#去掉scoped-但会污染全局样式" class="header-anchor">#</a> 去掉scoped，但会污染全局样式</h5> <h5 id="使用-deep-深度选择器-样式穿透"><a href="#使用-deep-深度选择器-样式穿透" class="header-anchor">#</a> 使用/deep/深度选择器，样式穿透</h5> <div class="language- line-numbers-mode"><pre class="language-text"><code>&lt;style scoped&gt;
   .my .el-input__inner{
      border-radius: 30px;/* 这个不起作用 */
   }
   .my /deep/ .el-input__inner{
      border-radius: 30px;/* 这个起作用 */
   }
&lt;/style&gt;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>当一个页面有多个相同组件，避免污染一个页面的样式，也可使用组合选择器精准修改个别组件样式</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>&lt;style lang='scss' scoped&gt;
/deep/ .buttonWrapper .el-button{
      background-color: red;
  }
&lt;/style&gt;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h5 id="使用-深度选择器-使用-如果是-less-sass-是无法识别的-此时需要使用-deep"><a href="#使用-深度选择器-使用-如果是-less-sass-是无法识别的-此时需要使用-deep" class="header-anchor">#</a> 使用<code>&gt;&gt;&gt;</code>深度选择器，使用<code>&gt;&gt;&gt;</code> ,如果是 less/sass 是无法识别的,此时需要使用 /deep/</h5> <div class="language- line-numbers-mode"><pre class="language-text"><code>&lt;style scoped&gt;
.form-box &gt;&gt;&gt; .el-input__inner {
	border-width: 0 0 2px 0;
}
&lt;/style&gt;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="less和scss"><a href="#less和scss" class="header-anchor">#</a> less和scss</h3> <h5 id="你为什么使用less和scss"><a href="#你为什么使用less和scss" class="header-anchor">#</a> 你为什么使用less和scss</h5> <p>​	LESS和SCSS都是css的预处理器,可以拥有变量,运算,继承,嵌套的功能,使用两者可以使代码更加的便于阅读和维护</p></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">3/1/2023, 1:02:23 PM</span></div></footer> <!----> <div class="comments-wrapper"><!----></div></main></div> <!----></div> <ul class="sub-sidebar sub-sidebar-wrapper" style="width:12rem;" data-v-b57cc07c data-v-7dd95ae2><li class="level-2" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#基础" class="sidebar-link reco-side-基础" data-v-b57cc07c>基础</a></li><li class="level-3" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#生命周期" class="sidebar-link reco-side-生命周期" data-v-b57cc07c>生命周期</a></li><li class="level-3" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#watch" class="sidebar-link reco-side-watch" data-v-b57cc07c>watch</a></li><li class="level-3" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#组件之间传值通信方法有哪些" class="sidebar-link reco-side-组件之间传值通信方法有哪些" data-v-b57cc07c>组件之间传值通信方法有哪些：</a></li><li class="level-3" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#v-for中key有什么作用" class="sidebar-link reco-side-v-for中key有什么作用" data-v-b57cc07c>v-for中key有什么作用</a></li><li class="level-3" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#nexttick的作用与原理" class="sidebar-link reco-side-nexttick的作用与原理" data-v-b57cc07c>nextTick的作用与原理</a></li><li class="level-3" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#vue-router" class="sidebar-link reco-side-vue-router" data-v-b57cc07c>Vue-router</a></li><li class="level-2" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#项目" class="sidebar-link reco-side-项目" data-v-b57cc07c>项目</a></li><li class="level-3" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#项目如何性能优化" class="sidebar-link reco-side-项目如何性能优化" data-v-b57cc07c>项目如何性能优化</a></li><li class="level-3" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#如何做权限管理" class="sidebar-link reco-side-如何做权限管理" data-v-b57cc07c>如何做权限管理</a></li><li class="level-3" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#如何修改element-ui默认样式" class="sidebar-link reco-side-如何修改element-ui默认样式" data-v-b57cc07c>如何修改element-ui默认样式</a></li><li class="level-3" data-v-b57cc07c><a href="/wxb-blog/views/%E6%8A%80%E6%9C%AF/%E9%9D%A2%E8%AF%95%E9%A2%98/Vue.html#less和scss" class="sidebar-link reco-side-less和scss" data-v-b57cc07c>less和scss</a></li></ul></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/wxb-blog/assets/js/app.8c0fb757.js" defer></script><script src="/wxb-blog/assets/js/4.900b5326.js" defer></script><script src="/wxb-blog/assets/js/1.627dfec7.js" defer></script><script src="/wxb-blog/assets/js/118.b53a6516.js" defer></script>
  </body>
</html>
